package com.dbuil.bleshoes.ui.fragment;


import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.blankj.utilcode.util.LogUtils;
import com.dbuil.bleshoes.R;
import com.dbuil.bleshoes.base.BaseFragment;
import com.dbuil.bleshoes.base.BasePagerFragment;
import com.dbuil.bleshoes.ui.fragment.childfragment.DarenFragment;
import com.dbuil.bleshoes.ui.fragment.childfragment.FindFragment;
import com.dbuil.bleshoes.ui.fragment.childfragment.GuanzhuFragment;
import com.dbuil.bleshoes.ui.fragment.childfragment.TuijianFragment;
import com.dbuil.bleshoes.ui.view.indicatortitles.FragmentAdapter;
import com.dbuil.bleshoes.ui.view.indicatortitles.NavigatorAdapter;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.ViewPagerHelper;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class LifeFragment extends BaseFragment {
    @BindView(R.id.life_indicator)
    MagicIndicator magicIndicator;
    @BindView(R.id.life_viewpager)
    ViewPager mPager;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_life;
    }

    @Override
    public void initImmersionBar() {
       // BarUtil.setWhiteStatusBarForFragment(this);
    }

    private List<String> mDataList;
    private List<BasePagerFragment> fragmentList;

    @Override
    public void initView() {
        super.initView();
        LogUtils.i(getString(R.string.life));
    }

    @Override
    public void initData() {
        super.initData();
        mDataList = new ArrayList<>();
        fragmentList = new ArrayList<>();

        fragmentList.add(new TuijianFragment());
        fragmentList.add(new GuanzhuFragment());
        fragmentList.add(new DarenFragment());
        fragmentList.add(new FindFragment());

        mDataList.add("推荐");
        mDataList.add("关注");
        mDataList.add("大人");
        mDataList.add("发现");

        showView();
    }

    private void showView() {


        FragmentPagerAdapter adapter = new FragmentAdapter(getChildFragmentManager(), fragmentList);

        //将适配器和ViewPager结合
        mPager.setAdapter(adapter);

        final CommonNavigator commonNavigator = new CommonNavigator(context);

//        if (mDataList.size() < 4) {
//            commonNavigator.setAdjustMode(true);//设置宽度等分
//        } else {
//            commonNavigator.setAdjustMode(false);
//        }

        commonNavigator.setAdjustMode(false);

        commonNavigator.setFollowTouch(true);
        commonNavigator.setAdapter(new NavigatorAdapter(mDataList, mPager));
        magicIndicator.setNavigator(commonNavigator);

        ViewPagerHelper.bind(magicIndicator, mPager);

    }



}
